//import { createPinia } from "pinia";
import { defineStore } from "pinia";
import { ref } from "vue";
import { get, post } from "@/plugins/axios";
import { Path } from "@/constant/index";
import VueCookie from "vue-cookies";
// export const pinia = createPinia();

export const userLoadingStore = defineStore("loading", () => {
  const loading = ref(false);
  function setLoading(val) {
    loading.value = val;
  }
  return { loading, setLoading };
});

export const userMenuStroe = defineStore(
  "menu",
  () => {
    const menu = ref([]);
    function setMenu(val) {
      menu.value = val;
    }
    return { menu, setMenu };
  },
  { persist: true }
);

// 存购物车的
export const useCartStore = defineStore(
  "cart",
  () => {
    const selectedGoods = ref([]);
    function setSelectedGoods(val) {
      selectedGoods.value = val;
    }
    return { selectedGoods, setSelectedGoods };
  },
  { persist: true }
);

// 存选取订单的
export const useCartItemStore = defineStore(
  "cart1", // 切记这个名字千万不要取重复
  () => {
    const selectedGoods = ref([]);
    function setSelectedGoods() {
      get(Path.cartGetByUid, null, (content) => {
        selectedGoods.value = content;
      });
    }
    return { selectedGoods, setSelectedGoods };
  },
  { persist: true }
);

export const useUserStore = defineStore(
  "loginUser",
  () => {
    const loginUser = ref({});
    function setLoginUser() {
      get(Path.getUserById, null, (content) => {
        loginUser.value = content;
      });
    }
    return { loginUser, setLoginUser };
  },
  { persist: true }
);
